package com.konsung.provide;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;

/**
 * 内容提供写入者.
 */

public class ProviderWriter {

    /**
     * 单个删除健康档案
     */
    private static final String URI_DELETE_HEALTH_FILE = "content://com.konsung" +
            ".publichealth/deleteHealthFile";

    /**
     * 删除全部健康档案
     */
    private static final String URI_DELETE_ALL_HEALTH_FILE = "content://com.konsung" +
            ".publichealth/deleteAllHealthFile";

    /**
     * 删除健康档案相关信息
     * @param context 上下文
     * @param selectionArgs 筛选条件 new String[]{身份证，会员卡}，如果没有，则传-1
     * @return 是否成功执行删除
     */
    public static boolean deleteHealthFile(Context context, String... selectionArgs) {
        try {
            if (selectionArgs.length == 2) {
                for (int i = 0; i < selectionArgs.length; i++) {
                    if (TextUtils.isEmpty(selectionArgs[i])) {
                        selectionArgs[i] = "-1";
                    }
                }
            } else {
                return false;
            }
            Uri uri = Uri.parse(URI_DELETE_HEALTH_FILE);
            ContentResolver resolver = context.getContentResolver();
            int result = resolver.delete(uri, null, selectionArgs);
            if (result == 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 删除健康档案相关信息
     * @param context 上下文
     * @return 是否成功执行删除
     */
    public static boolean deleteAllHealthFile(Context context) {
        try {
            Uri uri = Uri.parse(URI_DELETE_ALL_HEALTH_FILE);
            ContentResolver resolver = context.getContentResolver();
            int result = resolver.delete(uri, null, null);
            if (result == 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
